package com.globalresources.dao.hibernate;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.globalresources.dao.inface.IUserDao;
import com.globalresources.po.Authority;
import com.globalresources.po.User;
import com.trg.dao.dao.standard.GenericDAOImpl;
import com.trg.search.Filter;
import com.trg.search.ISearch;
import com.trg.search.Search;
import com.trg.dao.hibernate.BaseDAOImpl;


/**
 * @author aaron.lu(luzhiyuan) E-mail:atyuan.lu@gmail.com
 * @since 创建时间：Jul 5, 2009 2:00:57 PM
 */
public class UserDaoHibernate extends GenericDAOImpl<User, Integer> implements IUserDao {
	
	/**
	 * load user list
	*@author aaron.lu(luzhiyuan)
	*@param username
	*@return
	 */
	public List<User> getUsers(String username){
		Search search = new Search();
		search.addFilterLike("username", username);
		return search(search);
	}
	
	/**
	 * count users
	*@author aaron.lu(luzhiyuan)
	*@param username
	*@return
	 */
	public int countUsers(String username){
		Search search = new Search();
		search.addFilterLike("username", username);
		return count(search);
	}
	
	/**
	 * get User by username
	*@author aaron.lu(luzhiyuan)
	*@param username
	*@return
	 */
	public List<User> getUser(String username){
		Search search = new Search();
		search.addFilterEqual("username", username);
		return search(search);
	}
	/**
	 * save User 
	*@author songduanlei@gmail.com
	*@param object
	*@return
	 */
	
	public void saveUser(User user){
		super.save(user);		
		
	}
	
	/**
	 * save User 
	*@author songduanlei@gmail.com
	*@param object
	*@return
	 */
	
	public User getUserById(String id){
		return null;		
		
	}
	
	
	/**
	 * save Or Update User 
	*@author songduanlei@gmail.com
	*@param object
	*@return
	 */
	
	public void saveOrUpdateUser(User user){
		super._saveOrUpdate(user);
	}
	
	/**
	 * <P>查询用户
	*@author aaron.lu(luzhiyuan)
	*@param usernames
	*@return
	 */
	public List<User> getUsers(String[] usernames){
		Search search = new Search();
		Filter[] filters = new Filter[usernames.length];
		for (int i = 0; i < usernames.length; i++) {
			filters[i] = new Filter();
			filters[i].setOperator(Filter.OP_EQUAL);
			filters[i].setProperty("username");
			filters[i].setValue(usernames[i]);
		}
		search.addFilterOr(filters);
		return super.search(search);
	}
	
	
}
